package com.jr.util;

import java.util.Date;

/**
 * 日期差工具类
 *
 * @author 张闯
 * @since 1.0.0 2022-12-31
 */
public class DateCalculation {
    /**
     * @description: 计算两个日期之间的差
     * @author 张闯
     * @date: 2023/1/8 11:28
     * @param    endDate 结束时间
     * @param    nowDate 起始时间
     * @return: String
     */
    public static String getDatePoor(Date endDate, Date nowDate) {
        System.out.println(endDate + "================" + nowDate);
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        System.out.println(day + "天" + hour + "小时" + min + "分钟");
        if (day >= 1) {
            return day + "天";
        } else if (hour >= 1 && day < 1) {
            return hour + "小时";
        } else {
            return min + "分钟";
        }

    }
}
